package com.heyqing.topic.IsSameTree_0100;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * ClassName:IsSameTree
 * Package:com.heyqing.topic.IsSameTree_0100
 * Description:
 *
 * @Date:2024/9/12
 * @Author:Heyqing
 */
public class IsSameTree {
    private boolean flag = true;
    private boolean result = false;

    public boolean isSameTree(TreeNode p, TreeNode q) {
        LDRRecursive(p, q);
        return result;
    }

    private void LDRRecursive(TreeNode p, TreeNode q) {
        if (!flag) return;
        if (Objects.isNull(p) || Objects.isNull(q)) {
            if (Objects.isNull(p) && Objects.isNull(q)) {
                result = true;
                return;
            }
            result = false;
            flag = false;
            return;
        }
        LDRRecursive(p.left, q.left);
        if (p.val != q.val) {
            result = false;
            flag = false;
            return;
        }
        LDRRecursive(p.right, q.right);
    }
}
